package com.lagou.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

@ApiModel
public class ResponseResult<T> implements Serializable {

    @ApiModelProperty(value = "结果编码", required = true)
    private String code = ResponseCode.SUCCESS;

    @ApiModelProperty(value = "结果信息", required = true)
    private String msg;

    @ApiModelProperty(value = "结果数据", required = true)
    private T data;

    public ResponseResult() {
    }

    public ResponseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T>ResponseResult<T> success(String code, String message, T data) {
        return new ResponseResult<>(code, message, data);
    }

    public static <T>ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(ResponseCode.SUCCESS, message, data);
    }

    public static <T>ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResponseCode.SUCCESS, "操作成功", data);
    }

    public static <T>ResponseResult<T> exception(String code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    public static <T>ResponseResult<T> exception(String message) {
        return new ResponseResult<>(ResponseCode.BUSINESS_EXCEPTION, message, null);
    }

    public static <T>ResponseResult<T> exception(String code, String message, T data) {
        return new ResponseResult<>(code, message, data);
    }

    public static <T>ResponseResult<T> fail(String code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    public static <T>ResponseResult<T> fail(String message) {
        return new ResponseResult<>(ResponseCode.BUSINESS_EXCEPTION, message, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}